package com.fumin.quartz;

import com.fumin.mapper.UserMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Component
public class ClassesUpdater implements Job {

    @Autowired
    EhCacheCacheManager cacheManager;
    @Autowired
    UserMapper userMapper;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Cache cache = cacheManager.getCache("rankPool");
        List<Map<String,Long>> sqlResults = userMapper.selectRankData();
        for (int i = 0; i <sqlResults.size() ; i++) {
            Map<String,Long> temp= sqlResults.get(i);
            cache.put(temp.get("pk"),i+1);
        }
        Cache cache5 = cacheManager.getCache("fiveMinute");
        Map<String, Object> last = userMapper.selectLast();
        cache5.put("last",last);
    }
}